package com.ruoyi.guidance.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.guidance.domain.HealthGuidance;
import com.ruoyi.guidance.service.IHealthGuidanceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 健康指导Controller
 * 
 * @author ruoyi
 * @date 2025-01-06
 */
@RestController
@RequestMapping("/guidance/guidance")
public class HealthGuidanceController extends BaseController
{
    @Autowired
    private IHealthGuidanceService healthGuidanceService;

    /**
     * 查询健康指导列表
     */
    @PreAuthorize("@ss.hasPermi('guidance:guidance:list')")
    @GetMapping("/list")
    public TableDataInfo list(HealthGuidance healthGuidance)
    {
        startPage();
        List<HealthGuidance> list = healthGuidanceService.selectHealthGuidanceList(healthGuidance);
        return getDataTable(list);
    }

    /**
     * 导出健康指导列表
     */
    @PreAuthorize("@ss.hasPermi('guidance:guidance:export')")
    @Log(title = "健康指导", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HealthGuidance healthGuidance)
    {
        List<HealthGuidance> list = healthGuidanceService.selectHealthGuidanceList(healthGuidance);
        ExcelUtil<HealthGuidance> util = new ExcelUtil<HealthGuidance>(HealthGuidance.class);
        util.exportExcel(response, list, "健康指导数据");
    }

    /**
     * 获取健康指导详细信息
     */
    @PreAuthorize("@ss.hasPermi('guidance:guidance:query')")
    @GetMapping(value = "/{healthId}")
    public AjaxResult getInfo(@PathVariable("healthId") Long healthId)
    {
        return success(healthGuidanceService.selectHealthGuidanceByHealthId(healthId));
    }

    /**
     * 新增健康指导
     */
    @PreAuthorize("@ss.hasPermi('guidance:guidance:add')")
    @Log(title = "健康指导", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HealthGuidance healthGuidance)
    {
        return toAjax(healthGuidanceService.insertHealthGuidance(healthGuidance));
    }

    /**
     * 修改健康指导
     */
    @PreAuthorize("@ss.hasPermi('guidance:guidance:edit')")
    @Log(title = "健康指导", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HealthGuidance healthGuidance)
    {
        return toAjax(healthGuidanceService.updateHealthGuidance(healthGuidance));
    }

    /**
     * 删除健康指导
     */
    @PreAuthorize("@ss.hasPermi('guidance:guidance:remove')")
    @Log(title = "健康指导", businessType = BusinessType.DELETE)
	@DeleteMapping("/{healthIds}")
    public AjaxResult remove(@PathVariable Long[] healthIds)
    {
        return toAjax(healthGuidanceService.deleteHealthGuidanceByHealthIds(healthIds));
    }
}
